package com.jp.knowledge.adapter.team_circle;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.TeamCircleMessageModel;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.util.TimeUtil;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/7/20.
 */

public class TeamCircleMessageAdapter extends RecycleVAdapter<TeamCircleMessageModel> {

	public TeamCircleMessageAdapter(Context context, @NonNull List<TeamCircleMessageModel> list) {
		super(context, list);
	}

	@Override
	public int getLayoutId(int viewType) {
		return R.layout.item_team_circle_message;
	}

	@Override
	public void onBind(RecycleVHolder holder, int position) {
		TeamCircleMessageModel data = getData(position);
		holder.setImageUrl(R.id.team_circle_message_head, data.getPortrait());
		holder.setTextView(R.id.team_circle_message_name, data.getUserName());
		TextView messagaeTitle = holder.getTextView(R.id.team_circle_message_title);
		if(data.getRelationType() == 1){
			messagaeTitle.setText(data.getRelationContent());
			messagaeTitle.setCompoundDrawablesWithIntrinsicBounds(null,null,null,null);
		} else{
			messagaeTitle.setText("");
			messagaeTitle.setCompoundDrawablesWithIntrinsicBounds(
					mContext.getResources().getDrawable(R.mipmap.hollow)
					,null,null,null);
		}
		holder.setTextView(R.id.team_circle_message_time, TimeUtil.friendly_time(data.getCreateTime()));
		if(data.getScoopCover() != null && data.getScoopCover().trim().length() > 0){
			holder.get(R.id.team_circle_message_img).setVisibility(View.VISIBLE);
			holder.setImageUrl(R.id.team_circle_message_img, data.getScoopCover());
			holder.get(R.id.team_circle_message_desc).setVisibility(View.GONE);
		} else{
			holder.get(R.id.team_circle_message_img).setVisibility(View.GONE);
			holder.get(R.id.team_circle_message_desc).setVisibility(View.VISIBLE);
			holder.setTextView(R.id.team_circle_message_desc, data.getScoopContent());
		}
	}
}
